﻿@{
    ViewData["Title"] = "文章管理-基础设置";
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.CurrentMenuP = "ArticleNews";
    ViewBag.CurrentMenu = "ArticleNews/ArticleSetting";
}
@using Yuebon.WebApp.Commons;
@model Yuebon.CMS.Models.ArtSetting;

<div class="edit-page-wrapper">
    <div class="row">
        <div class="col-12">
            <form class="form-horizontal" id="frmSubmit" method="post" enctype="multipart/form-data">
                <div class="card">
                    <div class="card-header d-flex p-0">
                        <ul class="nav nav-pills p-2">
                            <li class="nav-item">
                                <a class="nav-link active" href="#basicInfo" data-toggle="tab">基本信息</a>
                            </li>
                        </ul>
                    </div><!-- /.card-header -->
                    <div class="card-body">
                        <div class="tab-content p-0">
                            <!-- Morris chart - Sales -->
                            <div class="chart tab-pane active" id="basicInfo" style="position: relative;">
                                <div class="form-group">
                                    <div class="row">
                                        <label for="SoftName" class="col-form-label col-md-2">应用名设置:</label>
                                        <input type="text" class="form-control col-md-5" name="AppName" id="AppName" value="@Model.AppName" placeholder="请输入应用名称">
                                        &nbsp;&nbsp;<span class="help-block">*默认名称为"头条"，应用名称最多4个字符</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="IsOpenPush" class="col-form-label col-md-2">开启推送:</label>
                                        <label for="IsTop">
                                            <input type="checkbox" class="flat-red" checked="@(Model.IsOpenPush)" name="IsOpenPush" id="IsOpenPush">
                                            开启推送
                                        </label>
                                        &nbsp;&nbsp;<span class="help-block">当前状态：开启，关闭后，前台头条导航将不显示“今日头条”分类</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="IsOpenAudit" class="col-form-label col-md-2">开启审核:</label>
                                        <label for="IsTop">
                                            <input type="checkbox" class="flat-red" checked="@Model.IsOpenAudit" name="IsOpenAudit" id="IsOpenAudit">
                                            开启审核
                                        </label>
                                        &nbsp;&nbsp;<span class="help-block">当前状态：开启，关闭后，前台留言无需审核自动显示</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="IsOpenRecommend" class="col-form-label col-md-2">开启推荐:</label>
                                        <label for="IsTop">
                                            <input type="checkbox" class="flat-red" checked="@Model.IsOpenRecommend" name="IsOpenRecommend" id="IsOpenRecommend">
                                            开启推荐
                                        </label>
                                        &nbsp;&nbsp;<span class="help-block">当前状态：开启，闭后，前台文章内容页将不显示精彩推荐模块</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="IsOpenReward" class="col-form-label col-md-2">开启赞赏:</label>
                                        <label for="IsTop">
                                            <input type="checkbox" class="flat-red" checked="@Model.IsOpenReward" name="IsOpenReward" id="IsOpenReward">
                                            开启赞赏
                                        </label>
                                        &nbsp;&nbsp;<span class="help-block">当前状态：开启，关闭后，前台文章内容页将不显示赞赏模块</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="RewardAmount" class="col-form-label col-md-2">赞赏金额:</label>
                                        <input type="text" class="form-control col-md-5" name="RewardAmount" id="RewardAmount" value="@Model.RewardAmount">
                                        &nbsp;&nbsp;<span class="help-block">*可为空，最多255个字符</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="ListTitle" class="col-form-label col-md-2">列表页显示标题:</label>
                                        <input type="text" class="form-control col-md-5" name="ListTitle" id="ListTitle" value="@Model.ListTitle">
                                        &nbsp;&nbsp;<span class="help-block">*可为空，最多60个字符</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="ListShareTitle" class="col-form-label col-md-2">列表页分享标题:</label>
                                        <input type="text" class="form-control col-md-5" name="ListShareTitle" id="ListShareTitle" value="@Model.ListShareTitle">
                                        &nbsp;&nbsp;<span class="help-block">*可为空，最多60个字符</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="ListShareDesc" class="col-form-label col-md-2">列表页分享详情:</label>
                                        <input type="text" class="form-control col-md-5" name="ListShareDesc" id="ListShareDesc" value="@Model.ListShareDesc">
                                        &nbsp;&nbsp;<span class="help-block">*可为空，最多255个字符</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="SysLogo" class="col-form-label col-2">列表页分享图:</label>
                                        <div class="input-group col-5">
                                            <input type="text" class="form-control upload-path" name="ListShareImage" id="ListShareImage" value="@Model.ListShareImage">
                                            <button type="button" id="j_upload_img_btn">选择图片</button>
                                            <ul id="upload_img_wrap"></ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="ImgUrlPic" class="col-form-label col-2"></label>
                                        <div class="input-group col-5">
                                            <img src="@Model.ListShareImage" alt="" id="ImgUrlPic" class="img-rounded" width="100" height="100" />
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="DetailShareBgImg" class="col-form-label col-2">详情页面海报背景图:</label>
                                        <div class="input-group col-5">
                                            <input type="text" class="form-control upload-path" name="DetailShareBgImg" id="DetailShareBgImg" value="@Model.DetailShareBgImg">
                                            <button type="button" id="j_upload_DetailShareBgImgimg_btn">选择图片</button>
                                            <ul id="upload_img_wrap"></ul>
                                        </div>&nbsp;&nbsp;<span class="help-block"> 只能上传【460px*736px】【PNG】【透明底】图片，否则将严重影响海报效果。</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="ImgUrlPicDetailShareBgImg" class="col-form-label col-2"></label>
                                        <div class="input-group col-5">
                                            <img src="@Model.DetailShareBgImg" alt="" id="ImgUrlPicDetailShareBgImg" class="img-rounded" width="100" height="100" />
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="ListNotice" class="col-form-label col-md-2">列表公告内容:</label>
                                        <input type="text" class="form-control col-md-5" name="ListNotice" id="ListNotice" value="@Model.ListNotice">
                                        &nbsp;&nbsp;<span class="help-block">*可为空，最多255个字符</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="ListNoticeUrl" class="col-form-label col-md-2">列表公告内容链接:</label>
                                        <input type="text" class="form-control col-md-5" name="ListNoticeUrl" id="ListNoticeUrl" value="@Model.ListNoticeUrl">
                                        &nbsp;&nbsp;<span class="help-block">*可为空，最多255个字符</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <label for="DetailCopyRight" class="col-form-label col-md-2">详情页版权说明:</label>
                                        <input type="text" class="form-control col-md-5" name="DetailCopyRight" id="DetailCopyRight" value="@Model.DetailCopyRight">
                                        &nbsp;&nbsp;<span class="help-block">*可为空，最多255个字符</span>
                                    </div>
                                </div>
                            </div>

                            <div class="modal-footer">
                                <button type="submit" class="btn btn-primary btnSave" id="btnSaveOK"><i class="fa fa-save"></i>保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<textarea id="uploadEditor" style="display: none;"></textarea>
<script type="text/javascript" charset="utf-8" src="~/lib/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="~/lib/ueditor/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="~/lib/ueditor/lang/zh-cn/zh-cn.js"></script>

<style type="text/css">
    label {
        text-align: right;
    }
</style>

<script type="text/javascript">
    var optUploadCurr = 0;
    // 实例化编辑器，这里注意配置项隐藏编辑器并禁用默认的基础功能。
    var uploadEditor = UE.getEditor("uploadEditor", {
        isShow: false,
        focus: false,
        enableAutoSave: false,
        autoSyncData: false,
        autoFloatEnabled: false,
        wordCount: false,
        sourceEditor: null,
        scaleEnabled: true,
        toolbars: [["insertimage", "attachment"]]
    });

    // 监听多图上传和上传附件组件的插入动作
    uploadEditor.ready(function () {
        uploadEditor.addListener("beforeInsertImage", _beforeInsertImage);
    });
    // 自定义按钮绑定触发多图上传和上传附件对话框事件
    document.getElementById('j_upload_img_btn').onclick = function () {
        var dialog = uploadEditor.getDialog("insertimage");
        dialog.title = '多图上传';
        dialog.render();
        dialog.open();
        optUploadCurr = 0;
    };
    // 自定义按钮绑定触发多图上传和上传附件对话框事件
    document.getElementById('j_upload_DetailShareBgImgimg_btn').onclick = function () {
        var dialog = uploadEditor.getDialog("insertimage");
        dialog.title = '多图上传';
        dialog.render();
        dialog.open();
        optUploadCurr = 1;
    };
    // 多图上传动作
    function _beforeInsertImage(t, result) {
        if (optUploadCurr == 0) {
            $("#ListShareImage").val(result[0].src);
            $("#ImgUrlPic").attr("src", result[0].src);
        } else if (optUploadCurr == 1) {
            $("#DetailShareBgImg").val(result[0].src);
            $("#ImgUrlPicDetailShareBgImg").attr("src", result[0].src);
        }
    };
    //checkbox实现单选
    $('inputp[type=checkbox]').click(function () {
        $(this).attr('checked', 'checked').siblings().removeAttr('checked');
    });
</script>
<!-- page script -->
<script>
    $(function () {
        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].flat-red').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal',
        });
        InitDictItem();
        BindSaveEvent();
    });
    //初始化数据字典
    function InitDictItem() {
    }
    //绑定保存按钮的事件
    function BindSaveEvent() {
        $("#btnSaveOK").click(function () {
            $("#frmSubmit").validate({
                rules: {
                    SoftName: {
                        required: true,
                        minlength: 2
                    },
                },
                messages: {
                    SoftName: {
                        required: "请输入应用名称",
                        minlength: "应用名称至少2个字符"
                    },
                },
                errorClass: 'help-block help-block-error',
                focusInvalid: true,
                //unhighlight: function (element, errorClass, validClass) { //验证通过
                //    $(element).tooltip('destroy').removeClass(errorClass);
                //},
                highlight: function (element) {//验证未通过
                    $(element).closest('.form-group').addClass('has-error');
                },
                success: function (label, element) {
                    $(element).closest('.form-group').removeClass('has-error');
                    //label.remove();
                    $(element).attr("title", "").tooltip("hide");
                    //alert(element);
                },
                errorPlacement: function (error, element) {
                    //element.parent('div').append(error);
                    if ($(element).next("div").hasClass("tooltip")) {
                        $(element).attr("data-original-title", $(error).text()).tooltip("show");
                    } else {
                        $(element).attr("title", $(error).text()).tooltip("show");
                    }
                },
                submitHandler: function (form) {
                    var postData = {
                        "AppName": $("#AppName").val(),
                        "IsOpenPush": $("#IsOpenPush").is(':checked'),
                        "IsOpenAudit": $("#IsOpenAudit").is(':checked'),
                        "IsOpenRecommend": $("#IsOpenRecommend").is(':checked'),
                        "IsOpenReward": $("#IsOpenReward").is(':checked'),
                        "RewardAmount": $("#RewardAmount").val(),
                        "ListShareTitle": $("#ListShareTitle").val(),
                        "ListShareDesc": $("#ListShareDesc").val(),
                        "ListShareImage": $("#ListShareImage").val(),
                        "DetailCopyRight": $("#DetailCopyRight").val(),
                        "ListNotice": $("#ListNotice").val(),
                        "ListNoticeUrl": $("#ListNoticeUrl").val(),
                        "ListTitle": $("#ListTitle").val(),
                        "DetailShareBgImg": $("#DetailShareBgImg").val(),

                    };
                    var reqUrl = "/CMS/ArticleNews/SaveSetting";
                    $.ajax({
                        url: reqUrl,
                        data: postData,
                        dataType: 'json',//服务器返回json格式数据
                        type: 'post',//HTTP请求类型
                        timeout: 100000,//超时时间设置为10秒；
                        success: function (data) {
                            //服务器返回响应，根据响应结果，分析是否登录成功；
                            if (data.Success) {
                                $("#frmSubmit")[0].reset();
                                toastr.success("操作成功");
                                setTimeout(function () {
                                    window.location.href = "/CMS/ArticleNews/ArticleSetting"
                                }, 1500);
                            } else {
                                toastr.warning("操作失败：" + data.ErrMsg);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            toastr.warning("操作失败：" + errorThrown);
                        }
                    });
                }
            });
        });
    }

</script>